#include "UDP_Server.hpp"
#include "DataRepo.hpp"
#include "Logger.h"
#include "Config.hpp"

int main( int argc, char* argv[] )
{
  try
  {
		if (argc != 5 )
		{
			std::cerr << "Usage: Server <ip> <port> <server name> <DistributedMode 0 : 1 >" << std::endl;
			return 1;
		}

		int port = atoi( argv[ 2 ] );
		std::string IP = argv[ 1 ];
		Logger logg( std::cout, true, false );
		DataRepo Repo;
		boost::asio::io_service io_service;
		std::string nn	= argv[ 3 ];
		logg<<"Starting Server: "<< nn <<"\n";
		DataType type	= (DataType)atoi( argv[ 4 ] );
		std::string otherServersPorts = "jjjj";
		bool DistMode ;

		if( atoi( argv[ 4 ] ) == 1  )
		{
			DistMode = true;
		}
		else
		{
			DistMode = false;
		}
		udp_server server(io_service ,IP , port, Repo, logg, nn , type , otherServersPorts , DistMode );
		io_service.run();

	}
	catch (std::exception& e)
	{
			std::cerr << e.what() << std::endl;
	}

  return 0;
}
